class Food {
	constructor(options = {}) {
		let opt = options;
		this.size = opt.size || 10;
		this.x =0;
		this.y=0;
		this.color = opt.color || '#ffc228';
		this.panel = opt.panel || {};
		this.foodArr = [];
	}
	render() {
		this.remove();
		let maxX = (this.panel.clientWidth / this.size) - 1;
		let maxY = (this.panel.clientHeight / this.size) - 1;
		
		// 创建食物
		let div = document.createElement('div');
		div.style.position='absolute';
		div.style.width = this.size + "px";
		div.style.height = this.size + "px";
		this.x = _.random(0, maxX)
		this.y = _.random(0, maxY)
		console.log(this.x ,this.y);
		div.style.left = this.x*this.size + "px";
		div.style.top =  this.y*this.size + "px";
		div.style.border='1px solid #012842';
		div.style.boxSizing='border-box';
		div.style.backgroundColor = this.color;
		// dom 缓存到数组
		this.foodArr.push(div)
		this.panel.appendChild(div)
	}
	remove(){
		if(!this.foodArr) return
		for(var i=this.foodArr.length-1;i>=0;i--){
			this.foodArr[i].remove()
			this.foodArr.splice(i,1)
		}
	}
	getPoint(){
		return {
			x:this.x || 0,
			y:this.y || 0
		}
	}
}
